﻿namespace FormCreator.Model
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using System.Text;

    /// <summary>
    /// This simple model wraps a propert of the given element.
    /// </summary>
    /// <typeparam name="T">The type of the value.</typeparam>
    public abstract class ElementValueBase<T>
    {
        /// <summary>
        /// The element.
        /// </summary>
        private object element;

        /// <summary>
        /// Initializes a new instance of the <see cref="ElementValueBase{T}" /> class.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="property">The property.</param>
        public ElementValueBase(object element, PropertyInfo property)
        {
            this.element = element;
            this.Property = property;
        }

        /// <summary>
        /// Gets or sets the value associated with the property.
        /// </summary>
        public virtual T Value
        {
            get
            {
                return (T)this.Property.GetValue(this.element, null);
            }

            set
            {
                this.Property.SetValue(this.element, value, null);
            }
        }

        /// <summary>
        /// Gets the displayed property.
        /// </summary>
        protected PropertyInfo Property { get; private set; }
    }
}
